﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rosieks.Web.Flow.Metadata;

namespace Rosieks.Web.Flow
{
    public class HiddenFieldStoreLocation : IStoreLocationPolicy
    {
        public string GetStoreLocation(WebflowContext webflowContext, System.Web.Mvc.ControllerContext context, StoreLocationOperation operation)
        {
            switch (operation)
            {
                case StoreLocationOperation.Load:
                    if (context.HttpContext.Request.RequestType == "GET")
                    {
                        return "TempData";
                    }
                    else
                    {
                        return "HiddenField";
                    }

                case StoreLocationOperation.Store:
                case StoreLocationOperation.Delete:
                    if (webflowContext.CurrentElement is Transition)
                    {
                        return "TempData";
                    }
                    else
                    {
                        return "HiddenField";
                    }
                default:
                    throw new ArgumentOutOfRangeException("operation");
            }
        }
    }
}
